package com.wlyuan.index.api.dto.combine;

import com.wlyuan.index.api.dto.Versioned;
import com.wlyuan.transport.constants.CombineStatusEnum;
import com.wlyuan.transport.dto.CombinePriceDetailDTO;
import com.wlyuan.transport.dto.query.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author yuanjie
 */
@Data
public class CombineIndexDTO implements Versioned, Serializable {
    @Data
    public static class Waybill implements Serializable {
        @ApiModelProperty("运单ID")
        private Long waybillId;
        @ApiModelProperty("合同号")
        private String contractNo;
        @ApiModelProperty("客户名称")
        private String customerName;
        @ApiModelProperty("客户ID")
        private Long customerId;
        @ApiModelProperty("收货方ID")
        private Long consigneeId;
        @ApiModelProperty("收货方名称")
        private String consigneeName;
    }

    @ApiModelProperty("合单主键")
    private Long combineId;

    @ApiModelProperty("合单号")
    private String combineNo;

    @ApiModelProperty("合同号")
    private String contractNo;

    @ApiModelProperty("发货时间")
    private LocalDateTime fromTime;

    @ApiModelProperty("到货时间")
    private LocalDateTime toTime;

    @ApiModelProperty("调度人")
    private UserDTO dispatchBy;

    @ApiModelProperty("调度操作时间")
    private LocalDateTime dispatchAt;

    @ApiModelProperty("总数量")
    private Integer totalQuantity;

    @ApiModelProperty("总重量(含补差)")
    private BigDecimal calculateWeight;

    @ApiModelProperty("总体积(含补差)")
    private BigDecimal calculateVolume;

    @ApiModelProperty("总价值(含补差)")
    private BigDecimal calculateValue;

    @ApiModelProperty("总重量(未含补差)")
    private BigDecimal totalWeight;

    @ApiModelProperty("总体积(未含补差)")
    private BigDecimal totalVolume;

    @ApiModelProperty("总价值(未含补差)")
    private BigDecimal totalValue;

    @ApiModelProperty("补差重量")
    private BigDecimal weightAddition;

    @ApiModelProperty("补差体积")
    private BigDecimal volumeAddition;

    @ApiModelProperty("补差价值")
    private BigDecimal valueAddition;

    @ApiModelProperty("签收数量")
    private Integer signTotalQuantity;

    @ApiModelProperty("签收异常数量")
    private Integer signExceptionQuantity;

    @ApiModelProperty("回单数量")
    private Integer receiptTotalQuantity;

    @ApiModelProperty("回单异常数量")
    private Integer receiptExceptionQuantity;

    @ApiModelProperty("合单状态 10 待调度 20 已委托 30 已完成")
    private Integer status;

    @ApiModelProperty("租户ID")
    private Long tenantId;

    @ApiModelProperty("创建人")
    private UserDTO createBy;

    @ApiModelProperty("创建时间")
    private LocalDateTime createAt;

    @ApiModelProperty("修改时间")
    private LocalDateTime updateAt;

    @ApiModelProperty("修改人")
    private UserDTO updateBy;

    @ApiModelProperty("接收时间")
    private LocalDateTime acceptAt;

    @ApiModelProperty("接收人")
    private UserDTO acceptBy;

    @ApiModelProperty("备注")
    private String desc;

    @ApiModelProperty(value = "关账状态 0：未关账，1已关账")
    private Integer billDayStatus;

    @ApiModelProperty(value = "关账状态描述")
    private String billDayStatusDesc;

    @ApiModelProperty("合单单客户")
    private CombineCustomerDTO customer;

    @ApiModelProperty("合单承运方")
    private CombineCarrierDTO carrier;

    @ApiModelProperty("运单列表")
    private List<Waybill> waybills;

    @ApiModelProperty("设备信息")
    private DeviceDetailDTO device;

    @ApiModelProperty("关单信息")
    private CloseDetailDTO close;

    @ApiModelProperty("费用信息")
    private CombinePriceDetailDTO price;

    @ApiModelProperty("版本号")
    private Long version;

    private boolean isAccepted() {
        return CombineStatusEnum.ACCEPTING == CombineStatusEnum.fromValue(this.status)
                || CombineStatusEnum.DONE == CombineStatusEnum.fromValue(this.status);
    }

    public Boolean getHasFees() {
        return this.isAccepted();
    }
}
